package com.automannn.codeGenerator.core.event;


import com.automannn.codeGenerator.core.context.Context;
import com.automannn.codeGenerator.core.introspection.Info;

public interface InvalidReferenceEventHandler extends EventHandler
{


     Object invalidGetMethod(Context context, String reference,
                             Object object, String property, Info info);

     boolean invalidSetMethod(Context context, String leftreference,
                                    String rightreference, Info info);

     Object invalidMethod(Context context, String reference,
                                Object object, String method, Info info);



     class InvalidGetMethodExecutor implements EventHandlerMethodExecutor
    {
        private Context context;
        private String reference;
        private Object object;
        private String property;
        private Info info;

        private Object result;

        InvalidGetMethodExecutor(
                Context context,
                String reference,
                Object object,
                String property,
                Info info)
        {
            this.context = context;
            this.reference = reference;
            this.object = object;
            this.property = property;
            this.info = info;
        }

        /**
         * Call the method invalidGetMethod()
         *
         * @param handler call the appropriate method on this handler
         */
        public void execute(EventHandler handler)
        {
            result = ((InvalidReferenceEventHandler) handler).invalidGetMethod(
                    context, reference, object, property, info);
        }

        public Object getReturnValue()
        {
            return result;
        }

        public boolean isDone()
        {
            return (result != null);
        }
    }

    /**
     * Defines the execution strategy for invalidGetMethod
     */
    static class InvalidSetMethodExecutor implements EventHandlerMethodExecutor
    {
        private Context context;
        private String leftreference;
        private String rightreference;
        private Info info;

        private boolean result;

        InvalidSetMethodExecutor(
                Context context,
                String leftreference,
                String rightreference,
                Info info)
        {
            this.context = context;
            this.leftreference = leftreference;
            this.rightreference = rightreference;
            this.info = info;
        }

        /**
         * Call the method invalidSetMethod()
         *
         * @param handler call the appropriate method on this handler
         */
        public void execute(EventHandler handler)
        {
            result = ((InvalidReferenceEventHandler) handler).invalidSetMethod(
                    context, leftreference, rightreference, info);
        }

        public Object getReturnValue()
        {
            return null;
        }

        public boolean isDone()
        {
            return result;
        }

    }

    /**
     * Defines the execution strategy for invalidGetMethod
     */
    static class InvalidMethodExecutor implements EventHandlerMethodExecutor
    {
        private Context context;
        private String reference;
        private Object object;
        private String method;
        private Info info;

        private Object result;
        private boolean executed = false;

        InvalidMethodExecutor(
                Context context,
                String reference,
                Object object,
                String method,
                Info info)
        {
            this.context = context;
            this.reference = reference;
            this.object = object;
            this.method = method;
            this.info = info;
        }

        /**
         * Call the method invalidMethod()
         *
         * @param handler call the appropriate method on this handler
         */
        public void execute(EventHandler handler)
        {
            executed = true;
            result = ((InvalidReferenceEventHandler) handler).invalidMethod(
                    context, reference, object, method, info);
        }

        public Object getReturnValue()
        {
            return result;
        }

        public boolean isDone()
        {
            return executed && (result != null);
        }

    }

}
